from flask import Blueprint, request

from algorithm_service import process_data
from data_modules.database_handler import DatabaseHandler

main_bp = Blueprint('main', __name__)

@main_bp.route('/submit', methods=['POST'])
def handle_submission():
    # 接收前端参数
    interests = request.form.getlist('interests')
    budget = request.form.get('budget')
    route_type = request.form.get('route_type')
    
    # 数据库查询
    db_handler = DatabaseHandler()
    query = db_handler.build_query(
        categories=interests,
        budget_limit=float(budget)
    )
    
    # 调用算法处理
    result = process_data(query.all())
    return {'status': 'success', 'data': result}